/*

METOO and MOIAUSSI! (C) Copyright Bill Buckels 1990 - 2008.
All rights reserved.
Apple //e ProDOS 8 Version 2.0

Written in Manx Aztec C65 Version 3.2b
MS-DOS cross-development environment

*/

/* picture show */

#include "me2.h"

ovmain(answers)
int answers;
{
  int ctr = 0;
  int idx;
  int c, pos=0, oldpos=0, action;
  int x1, x2, y3, arrowflag;

  arrowflag = 0;
  x1 = MXMAX /3;
  x2 = MXMAX - x1;
  y3 = (MYMAX / 191) * picpos[3][1];

  layout(0);

  /* if a mouse is in use set the
     initial position based on the mouse */
  if (mouseflag == 0) {
	  cmouse();
      if (mousex > x1) pos =  1;
      if (mousex > x2) pos =  2;
      if (multiples == 6 && mousey > y3) pos += 3;
      oldpos = pos;
  }

  for (;;) {

      for (idx = 0; idx < multiples; idx++) {
	     loadmini(ctr, idx);
	     picpos[idx][2] = ctr;
	     if (idx == pos) action = PUT;
	     else action = P_XOR;
	     showmini(idx, action, idx);
	     ctr++;
	     if (ctr>81)ctr = 0;
	  }
      showtext(picpos[pos][2],0);


      for (;;) {

		  c = kbhit();
		  if (c!=0)kbclear();

		  /* break on ESCAPE, SPACE, or ENTER */
		  if (c == 27 || c == 32 || c == 13)break;

		  if (c == LEFTARROW || c == RIGHTARROW) arrowflag = 1;

		  switch(c) {
			case LEFTARROW:  pos--;
			                 if (pos <0)pos = multiples-1;
			                 break;
			case RIGHTARROW: pos++;
			                 if (pos <multiples)break;
			                 pos = 0;
			                 break;
			case UPARROW:    if (multiples == 3)break;
			                 arrowflag = 1;
			                 pos -=3;
			                 if (pos < 0)pos+=6;
			                 break;
			case DOWNARROW:  if (multiples == 3)break;
			                 arrowflag = 1;
                             pos +=3;
                             if (pos > 5)pos-=6;
                             break;
            default:         if (mouseflag != 0 || arrowflag != 0) break;
            				 pos = 0;
            				 if (mousex > x1) pos =  1;
            				 if (mousex > x2) pos =  2;
            				 if (multiples == 3)break;
            				 if (mousey > y3) pos += 3;
		  }
          /* if position changes update the selected image */
		  if (pos != oldpos) {
		     showmini(oldpos, P_XOR, oldpos);
		     showtext(0,1);
		     showmini(pos, PUT,pos);
		     showtext(picpos[pos][2],0);
		     oldpos = pos;
		  }



	  }
      /* quit on ESCAPE */
	  if (c == 27)break;

	  showmini(pos, P_XOR, pos);
	  showtext(0,1); /* erase old text */

  }

  return 0;
}

